package com.junzhiit.nengji.shop.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.shop.service.BookingService;
import com.junzhiit.nengji.shop.web.vo.BookingEditVO;
import com.junzhiit.nengji.shop.web.vo.BookingSearchVO;
import com.junzhiit.nengji.shop.web.vo.BookingVO;
import com.junzhiit.nengji.shop.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/booking")
public class BookingController extends BaseController {
	
	@Autowired
	private BookingService bookingService;
	
	@ApiOperation(value = "取得所有预约订单")
	@RequestMapping( method = RequestMethod.GET)
	public ResultVO findAll(BookingSearchVO vo){
		AssertUtil.notBlank(vo.getShopId(), "shopId is required.");
		AssertUtil.notBlank(vo.getUserId(), "userId is required.");
		return bookingService.findAll(vo);
	}
	
	@ApiOperation(value = "取得桌子类型")
	@RequestMapping(value="/table/type", method = RequestMethod.GET)
	public ResultVO getTableType(String shopId){
		AssertUtil.notBlank(shopId, "shopId is required.");
		return bookingService.findTableTypeAll(shopId);
	}
	
	@ApiOperation(value = "生成预约订单")
	@RequestMapping( method = RequestMethod.POST)
	public ResultVO add(HttpServletRequest request,BookingVO booking){
		AssertUtil.notBlank(booking.getShopId(), "shopId is required.");
		AssertUtil.notBlank(booking.getUserId(), "userId is required.");
		AssertUtil.notBlank(booking.getTradeType(), "trade type is required.");
		AssertUtil.notBlank(booking.getWcId(), "wcId is required.");
		AssertUtil.notBlank(booking.getLinkmanName(), "linkman name is required.");
		AssertUtil.notBlank(booking.getLinkmanMobilePhone(), "linkman mobile phone is required.");
		AssertUtil.notNull(booking.getBookingType(),  "booking type is required.");
		AssertUtil.notNull(booking.getNumber(), "number is required.");
		AssertUtil.notNull(booking.getMoney(), "money is required.");
		AssertUtil.notNull(booking.getChooseTime(), "choose time is required.");
		return bookingService.add(request, booking);
	}
	
	@ApiOperation(value = "修改预约订单状态")
	@RequestMapping( method = RequestMethod.PUT)
	public ResultVO update(BookingEditVO vo){
		AssertUtil.notBlank(vo.getId(), "id is required.");
		AssertUtil.notNull(vo.getStatus(),  "status is required.");
		return bookingService.update(vo);
	}
}
